class Solution
{
public:
    string frequencySort(string s)
    {
        unordered_map<char, int> charCount;
        for (char c : s)
        {
            ++charCount[c];
        }
        auto compare = [&](char c1, char c2)
        {
            if (charCount[c1] == charCount[c2])
            {
                return c1 > c2;
            }
            return charCount[c1] > charCount[c2];
        };
        sort(s.begin(), s.end(), compare);
        return s;
    }
};